package com.example.baserapitaxi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public abstract class BaseLoginActivity extends Activity
{
	public static final int CHECK_LOGIN = 3392;
	public static final String booleanCheck = "check";
	
	protected EditText campoEmail;
	protected EditText campoClave;
	
	protected Button botonRegistro;
	
	protected boolean check;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_base_login);
		
		campoEmail = (EditText) findViewById(R.id.campoEmail);
		campoClave = (EditText) findViewById(R.id.campoClave);
		
		botonRegistro = (Button) findViewById(R.id.botonAceptarRegistroUsuario);
		
		Intent intent = getIntent();
		
		check = intent.getBooleanExtra(booleanCheck, false);
		
		if (check)
			botonRegistro.setVisibility(View.INVISIBLE);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.base_login, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings)
		{
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	public void aceptar (View view)
	{
		String email = campoEmail.getText().toString();
		String clave = campoClave.getText().toString();
		
		if (!checkString(email) || !checkString(clave))
		{
			toast("Debe llenar ambos campos.");
			return;
		}
		
		login(email, clave);
	}
	
	private boolean checkString (String check)
	{
		return check != null && !check.equals("");
	}
	
	private void toast (String mensaje)
	{
		Toast.makeText(BaseLoginActivity.this, mensaje, Toast.LENGTH_LONG).show();
	}
	
	protected abstract void login (String email, String clave);
	public abstract void registrar (View view);
}
